from dask.distributed import Client
from time import time
from dask import dataframe as dd

def square(x):
    return x ** 2

def fun(o):
    _sum = o.sum().compute()
    _mean = o.mean().compute()

    return _sum + _mean




# https://blog.csdn.net/qq_33826977/article/details/79920196
if __name__ == '__main__':
    ddf = dd.read_csv('AutoLoans.csv')

    client = Client('tcp://10.204.41.24:8000')
    for i in range(1000):
        MAX = 1000

        st = time()
        A = client.map(square, range(MAX))

        total = client.submit(sum, A)

        print('total:',total.result())
        total2 = client.submit(fun,ddf.id)
        print('total2:',total2.result())
        et = time()

        print(et - st)
